package com.api.shopapi.mapper;

import com.api.shopapi.entity.CheckinAssessGroup;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author maochuan
 */
@Repository
@Mapper
public interface CheckinAssessGroupMapper {
    @Insert("insert into checkin_assess_group " +
            "(CheckinAssessGroupCode,Name,MaxFraction,Sort,Status,StaffCode,InstitutionCode,CheckinAssessClassCode) " +
            "value(#{checkinAssessGroup.CheckinAssessGroupCode},#{checkinAssessGroup.Name}," +
            "#{checkinAssessGroup.MaxFraction},#{checkinAssessGroup.Sort}," +
            "#{checkinAssessGroup.Status},#{checkinAssessGroup.StaffCode},#{checkinAssessGroup.InstitutionCode},#{checkinAssessGroup.CheckinAssessClassCode})")
    int insert(@Param("checkinAssessGroup") CheckinAssessGroup checkinAssessGroup);

    @Delete("delete from checkin_assess_group where CheckinAssessGroupCode=#{checkinAssessGroupCode}")
    int deleteByCheckinAssessGroupCode(@Param("checkinAssessGroupCode") String checkinAssessGroupCode);

    @Update("update checkin_assess_group set Name = #{checkinAssessGroup.Name},MaxFraction=#{checkinAssessGroup.MaxFraction}," +
            "Sort=#{checkinAssessGroup.Sort},Status=#{checkinAssessGroup.Status}," +
            "StaffCode=#{checkinAssessGroup.StaffCode},InstitutionCode=#{checkinAssessGroup.InstitutionCode},CheckinAssessClassCode=#{checkinAssessGroup.CheckinAssessClassCode} " +
            "where CheckinAssessGroupCode=#{checkinAssessGroup.CheckinAssessGroupCode}")
    int updateByCheckinAssessGroupCode(@Param("checkinAssessGroup") CheckinAssessGroup checkinAssessGroup);

    @Select("<script>" +
            "select * from checkin_assess_group where InstitutionCode=#{institutionCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='status !=-1 '>" +
            "and Status =#{status} " +
            "</if>" +
            "<if test ='checkinAssessClassCode !=\"00000000-0000-0000-0000-000000000000\" '> " +
            "and CheckinAssessClassCode = #{checkinAssessClassCode} " +
            "</if>" +
            "order by Sort desc" +
            "</script>")
    List<CheckinAssessGroup> getListByInstitutionCode(@Param("institutionCode") String institutionCode,@Param("status") int status,@Param("checkinAssessClassCode") String checkinAssessClassCode,@Param("name") String name);

    @Select("select * from checkin_assess_group where CheckinAssessGroupCode=#{checkinAssessGroupCode} limit 1")
    CheckinAssessGroup getByCheckinAssessGroupCode(@Param("checkinAssessGroupCode") String checkinAssessGroupCode);

    @Select("select * from checkin_assess_group where Name=#{name} and InstitutionCode=#{institutionCode} limit 1")
    CheckinAssessGroup getByNameAndInstitutionCode(@Param("name") String name,@Param("institutionCode") String institutionCode);

    @Select("select * from checkin_assess_group where InstitutionCode=#{institutionCode} and Status=0 order by Sort desc")
    List<CheckinAssessGroup> getList(@Param("institutionCode") String institutionCode);

    @Select("select * from checkin_assess_group where CheckinAssessClassCode=#{checkinAssessClassCode} and Status=0 order by Sort desc")
    List<CheckinAssessGroup> getByCheckinAssessClassCode(@Param("checkinAssessClassCode") String checkinAssessClassCode);

    @Select("<script>" +
            "select * from checkin_assess_group" +
            " where InstitutionCode in (select institutionCode from institution where governmentCode=#{governmentCode}) " +

            "<if test ='name !=null and name!=\"\" '>" +
            "and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='status !=-1 '>" +
            "and Status =#{status} " +
            "</if>" +
            "<if test ='checkinAssessClassCode !=\"00000000-0000-0000-0000-000000000000\" '> " +
            "and CheckinAssessClassCode = #{checkinAssessClassCode} " +
            "</if>" +

            " order by Sort desc" +
            "</script>")
    List<CheckinAssessGroup> getListByGovCode(@Param("governmentCode") String governmentCode,
                                              @Param("status") int status,
                                              @Param("checkinAssessClassCode") String checkinAssessClassCode,
                                              @Param("name") String name);



}
